package cn.kent.base.join;

/**
 * 这种情况下使用后面会讲到的CountDownLatch是个不错的选择
 */
public class JoinTest {
    public static void main(String[] args) throws InterruptedException {

        Thread threadA = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("child threadA over");
            }
        });

        Thread threadB = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("child threadB over");
            }
        });
        // 启动子线程
        threadA.start();
        threadB.start();
        System.out.println("wait all child thread over.");
        // 等到子线程执行完毕，返回
        threadA.join();
        threadB.join();
        System.out.println("all child thread over!");
    }


}
